package com.springboot.dense.filter;

import com.springboot.dense.util.IPInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AdminLoginAdapter implements WebMvcConfigurer {

    //ip拦截
    //将自定义的拦截器定义为一个bean
    @Bean
    public HandlerInterceptor getMyInterceptor(){
        return new IPInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(new AdminLoginInterceptor());
        registration.addPathPatterns("/admin/**");
        registration.excludePathPatterns("/admin/login.html");
        //ip拦截
        registry.addInterceptor(getMyInterceptor()).addPathPatterns("/phone/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
